<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true"  label-width="100px">
      <el-form-item label="仓库名称" prop="warehouseName">
        <el-select
          v-model=" queryParams.warehouseName"
          placeholder="请选择仓库名称"
          clearable
          @keyup.enter.native="handleQuery"
        >
          <el-option v-for="item in warehouseList" :key="item.warehouseId" :label="item.warehouseName"
                     :value="item.warehouseName"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="vin码" prop="vehicleVin">
        <el-input
          v-model="queryParams.vehicleVin"
          placeholder="请输入vin码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="发动机号" prop="engineCode">
        <el-input
          v-model="queryParams.engineCode"
          placeholder="请输入发动机号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="到库日期" prop="arrivalDate">
        <el-date-picker clearable
                        style="width: 205px"
                        v-model="queryParams.arrivalDate"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择到库日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="品牌名称" prop="brandName">
        <el-input
          v-model="queryParams.brandName"
          placeholder="请输入品牌名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车系" prop="series">
        <el-input
          v-model="queryParams.series"
          placeholder="请输入车系"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="国家" prop="country">
        <el-input
          v-model="queryParams.country"
          placeholder="请输入国家"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车型名称" prop="modelName">
        <el-input
          v-model="queryParams.modelName"
          placeholder="请输入车型名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="颜色名称" prop="colorName">
        <el-input
          v-model="queryParams.colorName"
          placeholder="请输入颜色名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:inventory:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:inventory:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:inventory:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-upload2"
          size="mini"
          @click="handleImport"
          v-hasPermi="['system:inventory:import']"
        >导入</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:inventory:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="vehicleList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="车辆ID" align="center" prop="vehicleId" />
      <el-table-column label="仓库编码" align="center" prop="warehouseCode" />
      <el-table-column label="仓库名称" align="center" prop="warehouseName" />
      <el-table-column label="vin码" align="center" prop="vehicleVin" />
      <el-table-column label="数量" align="center" prop="vehicleNum" />
      <el-table-column label="入场状态" align="center" prop="inStatus" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_order_vehicle_in_out_status" :value="scope.row.inStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="装箱状态" align="center" prop="outStatus" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_order_vehicle_in_out_status" :value="scope.row.outStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="在库状态" align="center" prop="inventoryStatus" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_inventory_status" :value="scope.row.inventoryStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="到库日期" align="center" prop="arrivalDate" width="110">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.arrivalDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="装车日期" align="center" prop="loadingDate" width="110">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.loadingDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="品牌编码" align="center" prop="brandCode" />
      <el-table-column label="品牌名称" align="center" prop="brandName" />
      <el-table-column label="车系" align="center" prop="series" />
      <el-table-column label="国家" align="center" prop="country" />
      <el-table-column label="车型代码" align="center" prop="modelCode" />
      <el-table-column label="车型名称" align="center" prop="modelName" />
      <el-table-column label="颜色代码" align="center" prop="colorCode" />
      <el-table-column label="颜色名称" align="center" prop="colorName" />
      <el-table-column label="PI单号" align="center" prop="piCode" />
      <el-table-column label="PI配置描述" align="center" prop="piDescription" />
      <el-table-column label="英文描述" align="center" prop="englishDescription" />
      <el-table-column label="物料号(VC)" align="center" prop="materialCode" />
      <el-table-column label="发动机号" align="center" prop="engineCode" />
      <el-table-column label="改装单号" align="center" prop="refitCode" />
      <el-table-column label="MX订单号" align="center" prop="mxCode" />
      <el-table-column label="交车单位" align="center" prop="deliveryUnit" />
      <el-table-column label="交车人员" align="center" prop="deliveryPersonnel" />
      <el-table-column label="责任单位" align="center" prop="responsibleUnit" />
      <el-table-column label="运输工具号" align="center" prop="transportNumber" />
      <el-table-column label="质量交接编号" align="center" prop="qualityHandoverNumber" />
      <el-table-column label="装载位置" align="center" prop="loadingLocation" />
      <el-table-column label="责任分区" align="center" prop="responsibilityPartition" />
      <el-table-column label="分区" align="center" prop="subarea" />
      <el-table-column label="接车单位" align="center" prop="receivingUnit" />
      <el-table-column label="接车人员" align="center" prop="receivingPersonnel" />
      <el-table-column label="发现环节" align="center" prop="discoveryProcess" />
      <el-table-column label="运输方式" align="center" prop="transportType" />
      <el-table-column label="整备质量" align="center" prop="curbWeight" />
      <el-table-column label="长" align="center" prop="length" />
      <el-table-column label="宽" align="center" prop="width" />
      <el-table-column label="高" align="center" prop="high" />
      <el-table-column label="下线工厂" align="center" prop="offlineFactory" />
      <el-table-column label="下线时间" align="center" prop="offlineTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.offlineTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width"  fixed="right" width="120">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:inventory:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:inventory:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 添加或修改库存-车辆对话框 -->
    <el-dialog :title="title" :visible.sync="open"  append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-row>
          <el-col :span="24">
            <el-col :span="8">
              <el-form-item label="仓库名称" prop="warehouseName">
                <el-select
                  v-model=" form.warehouseName"
                  placeholder="请选择仓库名称"
                  clearable
                  @keyup.enter.native="handleQuery"
                >
                  <el-option v-for="item in warehouseList" :key="item.warehouseId" :label="item.warehouseName"
                             :value="item.warehouseName"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="vin码" prop="vehicleVin">
                <el-input v-model="form.vehicleVin" placeholder="请输入vin码" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="数量" prop="vehicleNum">
                <el-input v-model="form.vehicleNum" placeholder="请输入数量" />
              </el-form-item>
            </el-col>
          </el-col>

          <el-col :span="24">
            <el-col :span="8">
              <el-form-item label="到库日期" prop="arrivalDate">
                <el-date-picker clearable
                                style="width: 140px"
                                v-model="form.arrivalDate"
                                type="date"
                                value-format="yyyy-MM-dd"
                                placeholder="请选择到库日期">
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="品牌编码" prop="brandCode">
                <el-input v-model="form.brandCode" placeholder="请输入品牌编码" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="品牌名称" prop="brandName">
                <el-input v-model="form.brandName" placeholder="请输入品牌名称" />
              </el-form-item>
            </el-col>
          </el-col>
          <el-col :span="24">
            <el-col :span="8">
              <el-form-item label="车系" prop="series">
                <el-input v-model="form.series" placeholder="请输入车系" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="国家" prop="country">
                <el-input v-model="form.country" placeholder="请输入国家" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="车型代码" prop="modelCode">
                <el-input v-model="form.modelCode" placeholder="请输入车型代码" />
              </el-form-item>
            </el-col>
          </el-col>
          <el-col :span="24">
            <el-col :span="8">
              <el-form-item label="车型名称" prop="modelName">
                <el-input v-model="form.modelName" placeholder="请输入车型名称" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="颜色代码" prop="colorCode">
                <el-input v-model="form.colorCode" placeholder="请输入颜色代码" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="颜色名称" prop="colorName">
                <el-input v-model="form.colorName" placeholder="请输入颜色名称" />
              </el-form-item>
            </el-col>
          </el-col>
          <el-col :span="24">
            <el-col :span="8">
              <el-form-item label="PI单号" prop="piCode">
                <el-input v-model="form.piCode" placeholder="请输入PI单号" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="PI配置描述" prop="piDescription">
                <el-input v-model="form.piDescription" placeholder="请输入PI配置描述" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="英文描述" prop="englishDescription">
                <el-input v-model="form.englishDescription" placeholder="请输入英文描述" />
              </el-form-item>
            </el-col>
          </el-col>
          <el-col :span="24">
            <el-col :span="8">
              <el-form-item label="物料号(VC)" prop="materialCode">
                <el-input v-model="form.materialCode" placeholder="请输入物料号(VC)" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="发动机号" prop="engineCode">
                <el-input v-model="form.engineCode" placeholder="请输入发动机号" />
              </el-form-item>
            </el-col>
            <el-col :span="8">

              <el-form-item label="改装单号" prop="refitCode">
                <el-input v-model="form.refitCode" placeholder="请输入改装单号" />
              </el-form-item>
            </el-col>
          </el-col>
          <el-col :span="24">
            <el-col :span="8">
              <el-form-item label="MX订单号" prop="mxCode">
                <el-input v-model="form.mxCode" placeholder="请输入MX订单号" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="交车单位" prop="deliveryUnit">
                <el-input v-model="form.deliveryUnit" placeholder="请输入交车单位" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="交车人员" prop="deliveryPersonnel">
                <el-input v-model="form.deliveryPersonnel" placeholder="请输入交车人员" />
              </el-form-item>
            </el-col>
          </el-col>
          <el-col :span="24">
            <el-col :span="8">
              <el-form-item label="责任单位" prop="responsibleUnit">
                <el-input v-model="form.responsibleUnit" placeholder="请输入责任单位" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="运输工具号" prop="transportNumber">
                <el-input v-model="form.transportNumber" placeholder="请输入运输工具号" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="质量交接编号" prop="qualityHandoverNumber">
                <el-input v-model="form.qualityHandoverNumber" placeholder="请输入质量交接编号" />
              </el-form-item>
            </el-col>
          </el-col>
          <el-col :span="24">
            <el-col :span="8">
              <el-form-item label="装载位置" prop="loadingLocation">
                <el-input v-model="form.loadingLocation" placeholder="请输入装载位置" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="责任分区" prop="responsibilityPartition">
                <el-input v-model="form.responsibilityPartition" placeholder="请输入责任分区" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="分区" prop="subarea">
                <el-input v-model="form.subarea" placeholder="请输入分区" />
              </el-form-item>
            </el-col>
          </el-col>
          <el-col :span="24">
          <el-col :span="8">
            <el-form-item label="接车单位" prop="receivingUnit">
              <el-input v-model="form.receivingUnit" placeholder="请输入接车单位" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="接车人员" prop="receivingPersonnel">
              <el-input v-model="form.receivingPersonnel" placeholder="请输入接车人员" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="发现环节" prop="discoveryProcess">
              <el-input v-model="form.discoveryProcess" placeholder="请输入发现环节" />
            </el-form-item>
          </el-col>
        </el-col>
          <el-col :span="24">
            <el-col :span="8">
              <el-form-item label="整备质量" prop="curbWeight">
                <el-input v-model="form.curbWeight" placeholder="请输入整备质量" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="长" prop="length">
                <el-input v-model="form.length" placeholder="请输入长" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="宽" prop="width">
                <el-input v-model="form.width" placeholder="请输入宽" />
              </el-form-item>
            </el-col>
          </el-col>
          <el-col :span="24">
            <el-col :span="8">
              <el-form-item label="高" prop="high">
                <el-input v-model="form.high" placeholder="请输入高" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="下线工厂" prop="offlineFactory">
                <el-input v-model="form.offlineFactory" placeholder="请输入下线工厂" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="下线时间" prop="offlineTime">
                <el-date-picker clearable
                                v-model="form.offlineTime"
                                type="date"
                                style="width: 140px"
                                value-format="yyyy-MM-dd"
                                placeholder="请选择下线时间">
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-col>
          <el-col :span="24">
            <el-col :span="8">
              <el-form-item label="备注" prop="remark">
                <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
              </el-form-item>
            </el-col>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 车辆导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <div class="el-upload__tip" slot="tip">
            <el-checkbox v-model="upload.updateSupport" /> 是否更新已经存在的车辆数据
          </div>
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplate">下载模板</el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import {  allWarehouse } from '@/api/system/warehouse'
import { getToken } from "@/utils/auth";
import { listVehicle, getVehicle, delVehicle, addVehicle, updateVehicle } from "@/api/system/inventory";
export default {
  name: "Vehicle",
  dicts: ['sys_inventory_vehicle_status','sys_inventory_status','sys_order_vehicle_in_out_status'],
  data() {
    return {
      warehouseList: [],//所有仓库
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 库存-车辆表格数据
      vehicleList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        warehouseName: null,
        vehicleVin: null,
        vehicleNum: null,
        vehicleStatus: null,
        inventoryStatus: null,
        arrivalDate: null,
        brandCode: null,
        brandName: null,
        series: null,
        country: null,
        modelCode: null,
        modelName: null,
        colorCode: null,
        colorName: null,
        piCode: null,
        piDescription: null,
        englishDescription: null,
        materialCode: null,
        engineCode: null,
        refitCode: null,
        mxCode: null,
        deliveryUnit: null,
        deliveryPersonnel: null,
        responsibleUnit: null,
        transportNumber: null,
        qualityHandoverNumber: null,
        loadingLocation: null,
        responsibilityPartition: null,
        subarea: null,
        receivingUnit: null,
        receivingPersonnel: null,
        discoveryProcess: null,
        transportType: null,
        curbWeight: null,
        length: null,
        width: null,
        high: null,
        offlineFactory: null,
        offlineTime: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        warehouseName: [
          { required: true, message: "仓库名称不能为空", trigger: "blur" }
        ],
        vehicleVin: [
          { required: true, message: "vin码不能为空", trigger: "blur" }
        ],
        vehicleNum: [
          { required: true, message: "数量不能为空", trigger: "blur" }
        ],
        modelCode: [
          { required: true, message: "车型代码不能为空", trigger: "blur" }
        ],
      },
      // 用户导入参数
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/system/inventory/importData"
      },
    };
  },
  created() {
    this.getWarehouseList();
    this.getList();
  },
  methods: {
    //    获取仓库数据
    getWarehouseList() {
      allWarehouse({}).then((res) => {
        this.warehouseList = res.data
      })
    },
    /** 查询库存-车辆列表 */
    getList() {
      this.loading = true;
      listVehicle(this.queryParams).then(response => {
        this.vehicleList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        vehicleId: null,
        warehouseId: null,
        warehouseCode: null,
        warehouseName: null,
        vehicleVin: null,
        vehicleNum: null,
        vehicleStatus: null,
        inventoryStatus: null,
        arrivalDate: null,
        brandCode: null,
        brandName: null,
        series: null,
        country: null,
        modelCode: null,
        modelName: null,
        colorCode: null,
        colorName: null,
        piCode: null,
        piDescription: null,
        englishDescription: null,
        materialCode: null,
        engineCode: null,
        refitCode: null,
        mxCode: null,
        deliveryUnit: null,
        deliveryPersonnel: null,
        responsibleUnit: null,
        transportNumber: null,
        qualityHandoverNumber: null,
        loadingLocation: null,
        responsibilityPartition: null,
        subarea: null,
        receivingUnit: null,
        receivingPersonnel: null,
        discoveryProcess: null,
        transportType: null,
        curbWeight: null,
        length: null,
        width: null,
        high: null,
        offlineFactory: null,
        offlineTime: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.vehicleId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加库存-车辆";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const vehicleId = row.vehicleId || this.ids
      getVehicle(vehicleId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改库存-车辆";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.vehicleId != null) {
            updateVehicle(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addVehicle(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const vehicleIds = row.vehicleId || this.ids;
      this.$modal.confirm('是否确认删除库存-车辆编号为"' + vehicleIds + '"的数据项？').then(function() {
        return delVehicle(vehicleIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/inventory/export', {
        ...this.queryParams
      }, `inventory${new Date().getTime()}.xlsx`)
    },
    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "车辆导入";
      this.upload.open = true;
    },
    /** 下载模板操作 */
    importTemplate() {
      this.download('system/inventory/importTemplate', {
      }, `inventory_template_${new Date().getTime()}.xlsx`)
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
      this.getList();
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    }
  }
};
</script>
